package org.szgb.console.cxht.web;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.szgb.console.cxht.entity.CxhtLocationForm;
import org.szgb.console.cxht.entity.CxhtLocationFormItemTree;
import org.szgb.console.cxht.mapper.CxhtLocationFormMapper;
import org.szgb.console.cxht.service.CxhtLocationFormService;
import org.szgb.core.base.web.BaseController;
import org.szgb.core.utils.AjaxJson;

@Slf4j
@RestController
@RequestMapping(value = "/cxht/location/form")
public class CxhtLocationFormController extends BaseController<CxhtLocationFormService, CxhtLocationFormMapper, CxhtLocationForm> {
    @Autowired
    public CxhtLocationFormController(CxhtLocationFormService cxhtLocationFormService){
        super(cxhtLocationFormService);
    }

    @PostMapping("/issue")
    public AjaxJson issue(HttpServletRequest request, HttpServletResponse response) {
        service.issue();
        return  AjaxJson.success(request, response);
    }

    @PostMapping("/file")
    public AjaxJson file(HttpServletRequest request, HttpServletResponse response) {
        service.file();
        return  AjaxJson.success(request, response);
    }

    @PostMapping("/getByIdForItem")
    public AjaxJson getByIdForItem(@RequestBody CxhtLocationForm cxhtLocationForm, HttpServletRequest request, HttpServletResponse response) {
        return  AjaxJson.success(request, response).put("data", service.getByIdForItem(cxhtLocationForm.getId()));
    }

    @PostMapping("/saveItemByTree")
    public AjaxJson saveItemByTree(@RequestBody CxhtLocationFormItemTree cxhtLocationFormItemTree, HttpServletRequest request, HttpServletResponse response) {
        service.saveItemByTree(cxhtLocationFormItemTree);
        return  AjaxJson.success(request, response);
    }
}
